<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://www.trkj.com/tr1702/tags" prefix="my" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<script type="text/javascript"
	src="<c:url value="/js/jquery-easyui-1.5.5.6/jquery.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/js/jquery-easyui-1.5.5.6/jquery.easyui.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/js/jquery-easyui-1.5.5.6/locale/easyui-lang-zh_CN.js"/>"></script>
<link rel="stylesheet" type="text/css"
	href="<c:url value="/js/jquery-easyui-1.5.5.6/themes/default/easyui.css"/>" />
<link rel="stylesheet" type="text/css"
	href="<c:url value="/js/jquery-easyui-1.5.5.6/themes/icon.css"/>" />
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>组织结构版本</title>
	<style type="text/css">
		 
	</style>
</head>
<body>	
	<script type="text/javascript">
			var handler = function(){
		 <my:g id="75">
				$("<form method='get'>").appendTo(document.body).form({
						url:'organizationupdate',
						onSubmit:function(param){
								var vv=$('#cf-organizationalversion-tb').datagrid('getSelected');
								param['organsId']=vv.organsId;
								param['versionName']=$('#cf-organizationalversion-namessss').textbox('getText');
								param['organsRemark']=$('.cf-organizationalversion-remark').textbox('getText');
								param['organsState']=$('#cf-organizationalversion-state').textbox('getValue');
								
								//return $(this).form('validate');
						},
						success:function(v){
							//v = eval("(" + v + ")");
							$('#cf-organizationalversion-tb').datagrid('reload');
							$('#cf-organizationalversion-win').dialog('close');
						}					
				}).submit().appendTo(".abc");
			 </my:g>
			}
			$(function(){
					$.messager.progress({
						title:'进度条',
						msg:'打开中...'
					});
					setTimeout(function(){
						$.messager.progress('close');
						//$("#cf-organizationalversion-win").dialog("open");
					},500); 
				$("#cf-organizationalversion-add").linkbutton({
					onClick : function() {
						/* parent.$('.dialog-button a:eq(0)').show();
						parent.$('.dialog-button a:eq(1)').hide(); */
						$("#cf-organizationalversion-win").dialog('open');	
						$("#cf-zzjgbb-1").show();
						$("#cf-zzjgbb-2").hide();
						$("#cf-zzjgbb-3").hide();
						$('#cf-organizationalversion-namessss').textbox('setText',"");
						$('.cf-organizationalversion-start').textbox('setText',"");
						$('.cf-organizationalversion-end').textbox('setText',"");
						$('.cf-organizationalversion-remark').textbox('setText',"");
						//$('#cf-organizationalversion-state').textbox('setText',"");
					}
				});
				$("#cf-organizationalversion-refresh").linkbutton({
					onClick:function(){
						$('#cf-organizationalversion-tb').datagrid('reload');
					}
				});
				$("#cf-organizationalversion-tj").linkbutton({
					onClick : function() {
						$("#cf-organizationalversion-xz").dialog("open");
						//$("#cf-organizationalversion-f").form('clear');
						/* parent.$('.dialog-button a:eq(0)').show();
						parent.$('.dialog-button a:eq(1)').hide();
						parent.$('.dialog-button a:eq(2)').hide(); */
					}
				});
				   $("#cf-win-remove1").linkbutton({onClick:function(){
					     var vv=$('#cf-organizationalversion-tb').datagrid('getSelected');
					     if(!vv){
					    	 return;
					     }
					     	var bb=$('#cf-organizationalversion-tb').datagrid('getRowIndex',vv);
							//alert(vv.organsId+" "+bb);
							$('#cf-organizationalversion-tb').datagrid('deleteRow',bb);
						$("<form method='get'>").appendTo(document.body).form({
							url:'organizationalversion_remove',
							onSubmit: function(params){
								params["organsId"]=vv.organsId;
							},
							success:function(v){
								//v = eval("(" + v + ")");
								$('#cf-organizationalversion-tb').datagrid('reload');
							}
						}).submit().appendTo(".abc");	
						
					}});
				//验证表单
				 $.extend($.fn.validatebox.defaults.rules, {
						 organsIdverify: {
								 validator: function(value){
									var reg = /(\w)*/;  
									return reg.test(value);    
								 },message:'不能为空'  
						 },organsIdsverify:{
							 	validator: function(value){
									var reg=/(\w)*/;  
									return reg.test(value);    
								 },message:'不能为空'  
					 	},versionNamesverify:{
						 		validator:function(value){
								var reg=/(\w)*/;  
									return reg.test(value); 
							 	}, message:'不能为空 '  
				 		},organsStartdatesverify:{
					 			validator:function(value){
								var reg=/\d[0-9]+((-\d+)|(\/\d+)){2}/;  
								return reg.test(value); 
							 	}, message:'请输入正确的日期格式 '  
		 				},organsEnddatesverify:{
			 					validator:function(value){
								var reg=/\d[0-9]+((-\d+)|(\/\d+)){2}/;  
								return reg.test(value); 
			 					}, message:'请输入正确的日期格式  '  
 						},organsRemarksverify:{
	 							validator:function(value){
								var reg=/(\w)*/;  
								return reg.test(value); 
					 			}, message:'不能为空 '  
				 		},organsStatesverify:{
					 			validator:function(value){
								var reg=/(\w)*/;  
								return reg.test(value); 
					 	}, message:'不能为空 '  
				 					}      
					}); 
			
			 
				//查询组织表数据到  textbox
				$("#cf-organizationalversion-tb1").datagrid({
					onDblClickRow : function(index,row) {
						var vv=	$('#cf-organizationalversion-tb1').datagrid('getSelected');
						console.log(row.orgareaName);
			 			$('#cf-organizationalversion-iss').textbox('setValue',row.orgareaId1);
						$('#cf-organizationalversion-isss').textbox('setValue',row.orgareaName);
						$('#cf-organizationalversion-xz').dialog('close');
					}
				});
				
				//编辑
		 	$("#cf-organizationalversion-tb").datagrid({
					onDblClickRow : function(index,row) {
						    //alert(index);
						$("#cf-organizationalversion-win").dialog({onOpen:function(){
							/* parent.$('.dialog-button a:eq(0)').hide();
							parent.$('.dialog-button a:eq(1)').show(); */		 
							$("#cf-zzjgbb-1").hide();
							$("#cf-zzjgbb-2").show();
							$("#cf-zzjgbb-3").show();
						var vv=	$('#cf-organizationalversion-tb').datagrid('getSelected');//获取当前行
						if(!vv){
							return;
						}
							 	var sss= new Date(row.organsStartdate);
							 	var ddd= new Date(row.organsEnddate);
							$('#cf-organizationalversion-iss').textbox('setText',row.orgareaId1);
							$('#cf-organizationalversion-isss').textbox('setText',row.orgareaName);
							$('#cf-organizationalversion-namessss').textbox('setText',row.versionName);
							$('.cf-organizationalversion-start').textbox('setText',sss.toLocaleString());
							$('.cf-organizationalversion-end').textbox('setText',ddd.toLocaleString());
							$('.cf-organizationalversion-remark').textbox('setText',row.organsRemark);
							//$('#cf-organizationalversion-state').textbox('setText',row.organsState); 
						}});
						 
						   /*  var index = $('#tb').datagrid('getRowIndex', vv);
						    $("#iss").val(row.orgareaId); */
						  /*   //读取方式,根据row的字段row.xxx
						    //操作完成后更新到Grid
						   /*  $('#dg').datagrid('updateRow', {
						        //index: $('#dg').datagrid('getRowIndex', selected.Id),
						        index: $('#dg').datagrid('getRowIndex', selected),
						        row: msg.Department
						    }); */
						    $("#cf-organizationalversion-win").dialog('open');
							
					}
		 		});
			});	
	</script>
	<div class="abc"></div>
	<div id="cf-organizationalversion-tbs1">
	 	<my:g id="73">
   		 <a id="cf-organizationalversion-add" class="easyui-linkbutton" data-options="iconCls:'icon-mini-add',plain:true,text:'添加'"></a>
    	  </my:g>
		<a id="cf-organizationalversion-refresh" class="easyui-linkbutton" data-options="iconCls:'icon-mini-refresh',text:'刷新',plain:true,iconAlign:'right'"></a>
    	 <input  class="easyui-searchbox" data-options="label:'搜索',width:300,labelWidth:50,prompt:'版本名称',
     	searcher:function(value,name){
	       $('#cf-organizationalversion-tb').datagrid('load','organizationalversion_searchbox?versionName='+value);
     	 }"> 
		 <my:g id="74">
		<a style="margin-left:20px" id="cf-win-remove1" class="easyui-linkbutton" data-options="
		iconCls:'icon-remove',plain:true,text:'删除',href1:'fasong'"></a>
		</my:g>
  </div>
		<table id="cf-organizationalversion-tb" class="easyui-datagrid" data-options="
			url:'organizationpages',
			fitColumns:true,
			fit:true,
			nowrap:false,
			loading:true,
			pagination:true,
			rownumbers:true,
			singleSelect:true,
			pageSize:10,
    		pageList:[10,20,30,40,50],
			toolbar:'#cf-organizationalversion-tbs1',
			striped:true,
			method:'get'	
	">
		<thead>
		  <tr>
			<th id="cf-organizationalversion-idd1" data-options="field:'organsId',width:200,align:'center'">版本编号</th>
			<th id="cf-organizationalversion-names1" data-options="field:'versionName',width:200,align:'center'">版本名称</th>
			<th id="cf-organizationalversion-start1" data-options="field:'organsStartdate',width:200,align:'center',
				formatter:function(value,row,index){
	  				var unixTimestamp = new Date(value);
            		 return unixTimestamp.toLocaleString();
             },align:'center'
			">开始日期</th>
			<th id="cf-organizationalversion-end1" data-options="field:'organsEnddate',width:200,align:'center',
			formatter:function(value,row,index){
	  				var unixTimestamp1 = new Date(value);
            		 return unixTimestamp1.toLocaleString();
             }">结束日期</th>
			<th id="cf-organizationalversion-remark1" data-options="field:'organsRemark',width:200,align:'center'">备注</th>
			<th id="cf-organizationalversion-state1" data-options="field:'organsState',width:200,align:'center',
				formatter:function(value){
					if(value==0){
						return value='启用';
					}else{
						return value='未启用';
					}
				}
			">状态</th>
		  </tr>	
		</thead>
		<tbody></tbody>
		
	</table>
	<div id="cf-organizationalversion-win" class="easyui-dialog" data-options="width:420, height:400,
			title:'组织结构版本',
     		bodyCls:'enroll',
      		modal:true,
      		closed:true,
      		buttons:[{
	        	text:'添加',
				id:'cf-zzjgbb-1',
	        	iconCls:'icon-ok',
        		handler:function(){
          		 $('#cf-organizationalversion-f').form({
            		onSubmit:function(param){
            		 //验证表单
						 var cc=$('#cf-organizationalversion-iss').textbox('getValue'); 
					 console.log(cc);
						 
             		 return $(this).form('validate');
            		},
	           		 success:function(v){
	              		//$.messager.alert('提示','添加成功');
						$('#cf-organizationalversion-tb').datagrid('reload');
	              		$('#cf-organizationalversion-win').dialog('close');
	            	}
          	    }).submit();
       		  }
      		},{
        	text:'保存',
			id:'cf-zzjgbb-2',
        	iconCls:'icon-save',
	        	handler:handler
			},{
        	text:'清除',
			id:'cf-zzjgbb-3',
        	iconCls:'icon-cancel',
	        	handler:function(){
		          		$('#cf-organizationalversion-f').form('load',{
							organsId:'',
							versionName:'',
							organsStartdate:'',
							organsEnddate:'',
							organsRemark:'',
							organsState:'',
							organsIds:''
						});

	        	}
			},{
        	text:'取消',
			id:'cf-zzjgbb-4',
        	iconCls:'icon-undo',
	        	handler:function(){
	          		$('#cf-organizationalversion-win').dialog('close');
	        	}
			}
			]">
		<form id="cf-organizationalversion-f" action="enroll" method="get">
			<div class="cf-organizationalversion-line" style="margin-top:10px">
				        <input id="cf-organizationalversion-iss" class="easyui-textbox" name="organsId"
					data-options="label:'版本编号',width:175,required:true,validType:'organsIdverify'
					">
					<a id="cf-organizationalversion-tj" class="easyui-linkbutton" data-options="width:30,height:20,iconCls:'icon-mini-add'"></a>
					<input id="cf-organizationalversion-isss" class="easyui-textbox" name="organsIds" data-options="width:155, 
					searcher:function(value,name){
	       				$('#cf-organizationalversion-tb').datagrid('load','organizationalversion_searchbox?versionName='+value);
     	 			},required:true,validType:'organsIdsverify'
					">
			</div>
			
			<div class="cf-organizationalversion-line" style="margin-top:10px">
				        <input id="cf-organizationalversion-namessss" class="easyui-textbox" name="versionName"
					data-options="label:'版本名称',width:250,required:true,validType:'versionNamesverify'">
			</div>
			
			<div class="cf-organizationalversion-line" style="margin-top:10px">
				        <input class="easyui-datetimebox cf-organizationalversion-start" name="organsStartdate"
					data-options="label:'开始日期',width:250,required:true,validType:'organsStartdatesverify'">  
			</div>
			
			<div class="cf-organizationalversion-line" style="margin-top:10px">
				        <input class="easyui-datetimebox cf-organizationalversion-end" name="organsEnddate"
					data-options="label:'结束日期',width:250,required:true,validType:'organsEnddatesverify'">
			</div>
			
			<div class="cf-organizationalversion-line" style="margin-top:10px">
				        <input class="easyui-textbox cf-organizationalversion-remark" name="organsRemark"
					data-options="label:'备注',width:350,multiline:true
					,height:70,required:true,validType:'organsRemarksverify'">
			</div>
			<div class="cf-organizationalversion-line" style="margin-top:10px;margin-left:30px">
				     <!--    <input class="easyui-textbox " name="organsState"
					data-options="label:'状态',width:350,required:true,validType:'organsStatesverify'"> -->
					<select  id="cf-organizationalversion-state" class="easyui-combobox" name="organsState" style="width:0px;"
					data-options="label:'搜索',width:200,panelHeight:'auto',editable:false">   
					    <option value="0">启用</option>   
					    <option value="1">未启用</option>   
					</select> 
			</div>
		</form>
	</div>
			
	<div id="cf-organizationalversion-xz" class="easyui-dialog" data-options="width:420, height:400,
			title:'清单查找-组织 区域',
      		modal:true,
			closed:true,
      		buttons:[{
	        	text:'确定',
	        	iconCls:'icon-ok',
        		handler:function(){
						var vv=	$('#cf-organizationalversion-tb1').datagrid('getSelected');
					if(vv){
						$('#cf-organizationalversion-xz').dialog('close');
					 	$('#cf-organizationalversion-iss').textbox('setValue',vv.orgareaId1);
						$('#cf-organizationalversion-isss').textbox('setValue',vv.orgareaName);
       		  		}else{
						$.messager.alert('提示','请选择一行');
					}	
				}
      		},{
        	text:'取消',
        	iconCls:'icon-cancel',
	        	handler:function(){
	          		$('#cf-organizationalversion-xz').dialog('close');
	        	}
			}
			]"> 
			 
		<a id="cf-organizationalversion-adds"  style="margin-right:50px;margin-top:20px;float:right" class="easyui-linkbutton" 
		data-options="text:'搜索',disabled:'false',plain:true"></a>
			<div class="cf-organizationalversion-line" style="margin-top:20px;padding:0px 0px 20px 0px">
				        <input id="cf-organizationalversion-bbmc" class="easyui-searchbox" name="orgareaName"
					data-options="label:'区域名称',width:250,
					searcher:function(value,name){
	       				 $('#cf-organizationalversion-tb1').datagrid('load','organizationArea_searchbox?orgareaName='+value);
     	 			}
					">
			</div>
			
		<table id="cf-organizationalversion-tb1" class="easyui-datagrid" data-options="
			url:'areapages',
			fitColumns:true,
			fit:true,
			nowrap:false,
			loading:true,
			pagination:true,
			rownumbers:true,
			singleSelect:true,
			pageSize:10,
    		pageList:[10,20,30,40,50],
			striped:true,
			method:'get'	
	">
		<thead>
		  <tr>
			<th  data-options="field:'orgareaId1',width:200,align:'center'">区域编号编号</th>
			<th  data-options="field:'orgareaName',width:200,align:'center'">区域名称</th>
		  </tr>	
		</thead>
		<tbody></tbody>
	</table>
	</div>
</body>
</html>